package model

import (
	"errors"
	"gorm.io/gorm"
	"ppa/init/mysql"
)

type Categories struct {
	ID uint `json:"id" form:"categories_id" gorm:"primaryKey;autoIncrement;not null"`
	CategoriesName string `json:"categories_name"  form:"categories_name" gorm:"default:''"`
}

func (categories *Categories)GetCategoriesList() (*[]Categories,error) {
	var categoriesList *[]Categories
	err := mysql.SqlDB.Find(&categoriesList).Error
	if err != nil || errors.Is(err, gorm.ErrRecordNotFound) {
		return nil, errors.New("未查询到数据存在")
	}
	return categoriesList, nil
}